package demo1;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public enum TestEnum {
    RED("red", 1), GREEN("green", 2), BLACK("black", 3);
    private String name;
    private int Key;
    private TestEnum(String name, int Key) {
        this.name = name;
        this.Key = Key;
    }

    public static void reflectPrivateConstructor() throws ClassNotFoundException, NoSuchMethodException, InstantiationException, InvocationTargetException, IllegalAccessException {
        Class<?> classTestEnum = Class.forName("demo1.TestEnum");
        Constructor<?> declaredConstructorTestEnum = classTestEnum.getDeclaredConstructor(String.class, int.class,String.class, int.class);
        declaredConstructorTestEnum.setAccessible(true);
        TestEnum t = (TestEnum) declaredConstructorTestEnum.newInstance("父类参数",8,"子类参数", 6);
        System.out.println(t);
    }

    public static void main(String[] args) throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        reflectPrivateConstructor();
    }
}
